﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
using Ctrip.Automation.Framework.Lib;
using NUnit.Framework;
using System.IO;
using API.Taolx.Shopping.Common;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using System.Xml.Linq;
using Gallio.Framework;
using API.Taolx.Shopping.Business;
using Ctrip.Automation.Framework.Attribute;

namespace API.Taolx.Shopping.TestCase.Api_Product
{
    public class SetProductCache
    {
        [Test]
        [Description(" 设置产品详情接口，P1 case,验证IsSuccess as True")]
        [Priority(Priority.P1)]
        public void SetProductCacheVerifyResultCode()
        {
            string requestStr = String.Empty;
            string responseStr = String.Empty;
            string Url = "http://shoppingapi.test2.taolx.com/api/Product/SetProductCache";
            string str = File.ReadAllText(string.Format("./Request_json/Api-Product/SetProductCache.json"));
            //      requestStr = ProductPriceDate_case(str);
            //  MoreCheck(requestStr);
            PrepareRequest request = new PrepareRequest();
            requestStr = request.postAPIFunc(Url, str);

            //验证返回报文
            VerifyResponse verify = new VerifyResponse(requestStr);
            verify.VerifyResultDataByAttributeValue("True", "IsSuccess");
        }

        /// <summary>
        ///  获取价格日历接口
        /// </summary>
        private string ProductPriceDate_case(string str)
        {
            string requestStr = String.Empty;
            string responseStr = String.Empty;
            string Url = "http://shoppingapi.test2.taolx.com/api/Product/SetProductCache";
            //post发送请求报文
            requestStr = str;
            responseStr = SoaAPI.postAPI2(Url, str);
            //响应报文json格式化
            string decodeStr = responseStr;
            return decodeStr;
        }

        [Test]
        private void MoreCheck(string requestStr)
        {
            //检查点
            JObject jo = JObject.Parse(requestStr);
            string[] values = jo.Properties().Select(item => item.Value.ToString()).ToArray();
            string IsSuccess = values[1].ToString();
            string ErrorMessage = values[3].ToString();
           // var IsSuccess = jo.Properties().First(item => item.Name.ToString() == "IsSuccess").Value;
          //  var ErrorMessage = jo.Properties().First(item => item.Name.ToString() == "ErrorMessage");
            CtripAssert.AreEqual("True", IsSuccess);
            Trace.WriteLine(IsSuccess);
            Trace.WriteLine(ErrorMessage);
            Log.Info("返回IsSuccess:" + IsSuccess);
            Log.Info("返回ErrorMessage:" + ErrorMessage);
        }
    }
}
